home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1330 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  45 lines

  1. Path: msuvx2.memphis.edu!tangh
  2. From: tangh@cc.memphis.edu
  3. Newsgroups: comp.lang.c++
  4. Subject: Problem with file read/write
  5. Date: 10 Jan 96 08:08:08 -0500
  6. Organization: The University of Memphis
  7. Message-ID: <1996Jan10.080808@msuvx2.memphis.edu>
  8. NNTP-Posting-Host: msuvx2.memphis.edu
  9.  
  10. Hello, everyone.  I am trying to read a data file and read it into another file
  11. tab delimited.  Each field in the data file has fixed position.  I am using
  12. following code to read the string
  13.  
  14. ifstream in_fp;
  15. ifstream out_fp;
  16.  
  17. void main()
  18. {    
  19.     char infile = "test1.txt";
  20.     char outfile = "test2.txt";
  21.     char s1[80], s2[45], s3[7];
  22.     
  23.     ......  // open two files
  24.  
  25.  
  26.     in_fp.read(s1, 80);
  27.     s1[7] = '\09';  // insert a tab at position 7
  28.     s1[14] = '\09'; // insert a tab at position 14
  29.     s2[9] = '\09';  // insert a tab at pos 9 for the second line of record
  30.     strcat(s1, s2);       // merge two lines of record into one line
  31.  
  32.     out_fp.write(s1, 131);   // write to the output file
  33.  
  34.     ...  // close two files
  35. }
  36.  
  37. The problem is if there are record missing at certain position, it will read
  38. next field and move the field position.  Also, this piece of code also write
  39. some other garbge into the file.  Could someone help me see what's wrong with
  40. it?  Thanks, Hua.
  41.  
  42.     
  43.  
  44.  
  45.